package com.oldboy.servlet.action;

import java.io.IOException;
import java.lang.ref.ReferenceQueue;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginAction extends HttpServlet {


	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("显式提交");
		
	}

	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("隐式提交");
		//1.接收数据
		String username = req.getParameter("username");
		String password = req.getParameter("password");
		//2.处理数据
		if(username.equals("admin") && password.equals("123456")){
			//用户名和密码正确
			//3.跳转页面
			req.setAttribute("username", "123111");
			req.getRequestDispatcher("/jsp/success.jsp").forward(req, resp);
		}else{
			//不正确
			//3.跳转页面
			req.setAttribute("msg", "用户名或者密码错误");
			req.getRequestDispatcher("/jsp/login.jsp").forward(req, resp);
		}
		
	}

}
